/***********************
*DESC:联动配置
*Author:wff 
*Date:2015-05-18
*
************************/
function GetReactorAddtableResult(gridId)
{
	var data=[];
	data = $.fn.tables.GetReactorAddtableResult(gridId);
	return data;
}
function GetCurrElemReactorData(currid, curepid, curval, curoid)
{
	
	var isINsert = false;
	if(CurrElemTriggerArry.length == 0){
			
		return false;
	}
	else{
		//var ers = new Array;
		var ers;
		$.each(CurrElemTriggerArry,function(index,item){
			if(item.t_epid == curepid && item.rid == currid  && item.val == curval && item.oid == curoid){
				if(item.hasOwnProperty("i")){
								
					if(item.i == 0)
						isINsert = false;
					else{
						isINsert = true;
						var NewtriggerI = item.i;
						if(typeof(NewtriggerI) == "object" && NewtriggerI.constructor == Array)										
							ers = item.i;
						else{
							ers = [];
							ers.push(NewtriggerI);
						}
					}
											
				}
				else{
					isINsert = false;
					return false;
				}
				return false;
			}
		})
		if(isINsert == false){
				
			return false;
		}
		else{
			
			return ers;
		}
	}
	
}
function InitReactorTableData(curepid, curval, cmdarry)
{	
	//$.fn.tables.bindObjData('ReactorAddtable', eval(cmdarry));
	$.fn.tables.loadReatorData('ReactorAddtable', eval(cmdarry));
}
function InitReactorForm()
{
		var trHtml = $("#ReactorAddtable").find("tr").slice(1).first().html();
		$("#ReactorAddtable").find("tbody").find("tr").remove();
		$("#ReactorAddtable").append("<tr>" + trHtml + "</tr>");
		/*********add************/
		var $floorid = $("#ReactorAddtable" + " #floorid");
        var $e_epid = $("#ReactorAddtable" + " #e_epid");
		var $oid = $("#ReactorAddtable" + " #oid");
		var $val = $("#ReactorAddtable" + " #val");
		InitFloorOption($floorid);
}

function GetReactorFrom(obj)
{	
	var ispass = validateRow('TriggerAddtable');
	if(!ispass){
		$.formSmallInit();
		
		return;
	}
	$.fn.tables.GetReactorFrom(obj);
}
/*存储联动内容数据*/
function AddReactorAction(currid, curepid, curval, curoid)
{
	if(currid == "" || currid == null || currid == undefined)
	{
		alert("请先保存触发条件后再配置联动内容");
		return;
	}
	var Tab = GetReactorAddtableResult('ReactorAddtable');
	if(Tab != 0){
		var ispass = validateRow('ReactorAddtable');
		if(!ispass){
			$.formSmallInit();
			
			return;
		}
	}
	//var trResult = "{" + '"t_epid"' +":"+ '"'+curepid+ '"'+","+'"val"'+":"+ '"'+ curval+ '"'+","+'"i"'+":"+"[" +getRowResult('ReactorAddtable') +"]" +"}";
	/*已有epid TriggerArry对象中先删除*/
	
	//对Tab数组进行倒序操作
	var TabArry = new Array();
	for (var i = 0; i < Tab.length; i++) {
		TabArry.push(Tab[Tab.length-i-1]);
	}
	Tab = TabArry; 	
	//对CurrElemTriggerArry数组进行倒序操作
//	var newArry = new Array();
//	for (var i = 0; i < CurrElemTriggerArry.length; i++) {
//		newArry.push(CurrElemTriggerArry[CurrElemTriggerArry.length-i-1]);
//	}
//	CurrElemTriggerArry = newArry; 
	
	 if(CurrElemTriggerArry.length != 0){	 		  
		 $.each(CurrElemTriggerArry,function(index,item){
			if(item.t_epid == curepid && item.val == curval && item.oid == curoid && item.rid == currid ){				
				CurrElemTriggerArry.splice(index, 1,{"rid": currid,"t_epid": curepid,"val": curval,"oid": curoid,"i": Tab});				
				return false; //删除完成退出遍历
			}				
		 })
		 
		  //CurrElemTriggerArry.push();
	  }
	  else {
		  CurrElemTriggerArry.push({"rid": currid,"t_epid": curepid,"val": curval,"oid": curoid,"i": Tab});  
	  }
	 	
	 //$('#TriggerAddModal').modal('hide');
	alert("修改成功");	
}
function GetTriggerAddtableResult(gridId)
{
	var data=[];
	data = $.fn.tables.GetTriggerAddtableResult(gridId);
	return data;
}
function GetCurrElemTriggerData(curepid)
{
	var isINsert = false;
	if(CurrElemTriggerArry.length == 0){
			
		return false;
	}
	else{
		var ers = [];
		ers = $.grep(CurrElemTriggerArry,function(item, index){
			if(item.t_epid == curepid)
				return true;
		},false);
		if(ers.length != 0)
			isINsert = true;
		
		if(isINsert == false){
				
			return false;
		}
		else{
				
			return ers;
		}
	}			
}
function InitTriggerTableData(curepid, cmdarry)
{	
	$.fn.tables.loadTriggerData('TriggerAddtable', eval(cmdarry));
}
function InitTriggerForm(curepid)
{
		var trHtml = $("#TriggerAddtable").find("tr").slice(1).first().html();
		$("#TriggerAddtable").find("tbody").find("tr").remove();
		$("#TriggerAddtable").append("<tr name ='FirstTr' id=1>" + trHtml + "</tr>");
		/*********add************/
		$("#TriggerAddtable" + " #t_epid").val(curepid);
		$("#TriggerAddtable" + " #t_epid").attr("value",curepid);
		$("#TriggerAddtable" + " #t_epname").val(GetEtypeName(curepid));
		$("#TriggerAddtable" + " #t_epname").attr("value",GetEtypeName(curepid));
		var $oid = $("#TriggerAddtable" + " #oid");
		var $val = $("#TriggerAddtable" + " #val");
		$val.val("");
		$val.attr("readonly","readonly");
		$val.attr("disabled","disabled");
		$val.empty();
		InitOidOptionByTrigger(curepid, $oid);
}
function GetTriggerFrom(curepid)
{
	nowepid = curepid;
	$('#t_epid').val(curepid);
	$("#t_epid").attr("value",curepid);
	$('#TriggerAddModal .input-small').removeClass("error");
	$('#TriggerAddModal .text-error').remove();
	$('#TriggerAddModal').modal('show');
	$('#ReactorAddModal').hide();
	$("#TriggerAddModal_addbtn").attr("onclick","AddTriggerAction('"+curepid+"');");
	var cmddata = GetCurrElemTriggerData(curepid);
	
	if(cmddata == false)
	{
		//$('#TriggerRowAddA').removeAttr("onclick");
		//$("#TriggerRowAddA").attr("onclick","addTableRow('TriggerAddtable')");
		InitTriggerForm(curepid);
		
		
	}
	else
	{
		//$('#TriggerRowAddA').removeAttr("onclick");
		//$("#TriggerRowAddA").attr("onclick","addTriggerRow('TriggerAddtable')");
		InitTriggerTableData(curepid, cmddata);
		
	}
	currDelTriggerIds = "";
}
function AddTriggerAction(curepid)
{
	
		var isEdit =  false;		
		var AddTab = GetTriggerAddtableResult('TriggerAddtable');
		
		if(AddTab != 0){
			var ispass = validateRow('TriggerAddtable');
			if(!ispass){
				$.formSmallInit();
				
				return;
			}
		}
		
		if(CurrElemTriggerArry.length != 0){
			var ers = [];
			ers = $.grep(CurrElemTriggerArry,function(item, index){
				if(item.t_epid == curepid)
					return true;
			},false);
			var isNotNeed = false;
			
			if(ers.length >0){//已有联动的编辑
				isEdit =  true;
				var Delrules = currDelTriggerIds.split(",");
				for (var i = 0; i < Delrules.length; i++) {	//删除
					var curridid = Delrules[i];
					var isDelStatus = false;
					 $.each(CurrElemTriggerArry,function(index,item){
						if(item.t_epid == curepid && item.rid == curridid){								
									CurrElemTriggerArry.splice(index, 1);				
									return false;
															
						}				
					 })
				}
				if(AddTab == 0){
					 $('#TriggerAddModal').modal('hide');
	 				$('#ReactorAddModal').hide();
					return;
				}
				$.each(AddTab,function(indexTr,itemTr){
					if(itemTr.rid == "" || itemTr.rid == null || itemTr.rid == undefined){//增加
							var ir = '0';
							triggeridint ++;
							CurrElemTriggerArry.push({"rid": triggeridint,"t_epid": curepid,"val": itemTr.val,"oid": itemTr.oid,"i": ir});
							return true;
					}
						
					$.each(CurrElemTriggerArry,function(index,item){
						
						if(item.t_epid == curepid && itemTr.rid == item.rid){//修改
								if(item.val == itemTr.val && itemTr.oid == item.oid)													
									return false;
								else{
									item.val = itemTr.val;
									item.oid = itemTr.oid;
									return false;
								}									
							
						}				
					 })
													
	 			})
				
			}else{//第一次保存
				if(AddTab == 0){
					 $('#TriggerAddModal').modal('hide');
	 				$('#ReactorAddModal').hide();
					return;
				}
				$.each(AddTab,function(indexTr,itemTr){
						var ir = '0';
						triggeridint ++;
						CurrElemTriggerArry.push({"rid": triggeridint,"t_epid": curepid,"val": itemTr.val,"oid": itemTr.oid,"i": ir});								
	 			})
				
			}
			
				 
	  }else{
		  $.each(AddTab,function(indexTr,itemTr){
						var ir = '0';
						triggeridint ++;
						CurrElemTriggerArry.push({"rid": triggeridint,"t_epid": curepid,"val": itemTr.val,"oid": itemTr.oid,"i": ir});								
	 	 })
	  }
		//对CurrElemTriggerArry数组进行倒序操作
		var TriggerArry = new Array();
		for (var i = 0; i < CurrElemTriggerArry.length; i++) {
			TriggerArry.push(CurrElemTriggerArry[CurrElemTriggerArry.length-i-1]);
		}
		CurrElemTriggerArry = TriggerArry; 
		
	 //$('#TriggerAddModal').modal('hide');
	 $('#ReactorAddModal').hide();
	 GetTriggerFrom(curepid);	
	
}

/*******联动配置管理界面根据epid获取etypename********/
function GetEtypeName(curepid)
{	
	var name = "";
	$.each(CurrElemArry,function(index,elem){
		if (elem.epid == curepid) {
			name = elem.etypename;
		}
	});
	return name;
}

/*******根据文本值改变select选中项********/
function ChangeSelectByText($select, text) 
{
	for (var i=0; i<$select.find("option").length; i++) {
		if ($select.get(0).options[i].text == text) {
			$select.get(0).options[i].selected = true;
			break;
		}
	}	
}

/*******联动配置管理界面floorid选项改变联动********/
function GetCurrAidGroup(obj)
{	
	var $raw      = $(obj).closest('tr');
	var $aid      = $raw.find('#aid');
	
	var $e_epid   = $raw.find('#e_epid');  
	var $epid   = $raw.find('#epid'); 
	
	var $oid      = $raw.find('#oid');
	var $val      = $raw.find('#val');
	var $delay    = $raw.find('#delay');
	   
	var floorid  = obj.value;
	var currname  = $(obj).find("option:selected").text();
	if ($epid.length == 0) {
		$e_epid.val("");
	}
	else {
		$epid.val("");
	}	
	$oid.val("");
	$val.val("");
	$delay.val("");
	InitAreaOption(floorid, $aid);
}

/*******联动配置管理界面aid选项改变联动********/
function GetCurrEpidGroup(obj)
{	
	var $raw      = $(obj).closest('tr');
	var $oid      = $raw.find('#oid');
	var $aid      = $raw.find('#aid');
	var $val      = $raw.find('#val');
	var $delay    = $raw.find('#delay');
	var $e_epid   = $raw.find('#e_epid');
	var $epid     = $raw.find('#epid');
	var aid       = obj.value;
	var floorid   = $raw.find('#floorid').val();
	var currname  = $(obj).find("option:selected").text();
	$oid.val("");
	$val.val("");
	$delay.val("");
	if ($epid.length == 0) {
		InitEpOption(floorid, aid, $e_epid);
	}
	else {
		InitEpOption(floorid, aid, $epid);
	}
	
}


/*******联动配置管理界面e_epid选项改变联动********/
function GetCurrOidGroup(obj)
{	
	var $raw      = $(obj).closest('tr');
	var $oid      = $raw.find('#oid');
	var $val      = $raw.find('#val');
	var $delay    = $raw.find('#delay');
	var currepid  = obj.value;
	var currname  = $(obj).find("option:selected").text();
	$val.val("");
	$delay.val("");
	InitOidOption(currepid, $oid);
}

/*******联动配置管理界面oid选项改变联动********/
function GetCurrValGroup(obj)
{	
	var $raw = $(obj).closest('tr');
	var $val = $raw.find('#val');
	var $delay = $raw.find('#delay');
	var curroid=obj.value;
	var currname=$(obj).find("option:selected").text();
	$val.val("");
	$delay.val(0);
	$val.attr("readonly","readonly");
	$val.attr("disabled","disabled");
	if (curroid == "" || curroid == null ){
		return;
	}
	SetValState(nowepid,currname,$val);
}
//联动配置管理界面中联动配置的oid选项改变联动
function GetCurrReactorValGroup(obj)
{	
	var $raw = $(obj).closest('tr');
	var $val = $raw.find('#val');
	var $delay = $raw.find('#delay');
	///////////有些表格epid的id不同，这里为了函数复用/////////////
	var $e_epid = $raw.find('#e_epid');
	var $epid = $raw.find('#epid');
	///////////////////////
	var curroid=obj.value;
	var currname=$(obj).find("option:selected").text();
	$val.val("");
	$val.attr("readonly","readonly");
	$val.attr("disabled","disabled");
	$delay.val(0);
	if (curroid == "" || curroid == null ){
		return;
	}
	if ($epid.length == 0) {
		SetValState($e_epid.val(),currname,$val);
	}
	else {
		SetValState($epid.val(),currname,$val);
	}
}

/*******联动配置管理界面初始化oid选项********/
function InitOidOptionByTrigger(curepid, $oid) {

	$oid.empty();
	/******场景特例******/
	var isScene = false;
	$.each(CurrElemArry, function (index, elem) {
		if (elem.epid == curepid) {
			if (elem.etype == '01') {
				isScene = true;
			}
		}
	});
	if (isScene == true) {
		$.each(CurrElemCMDArry, function (index, elemCmd) {
			if (elemCmd.epid == curepid) {
				$oid.append("<option select='selected' value=''>" + "" + "</option>");
				if (typeof(elemCmd.ccmd) == 'undefined') {
					return;
				}
				if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
					if (elemCmd.ccmd.i != 0) {
						$.each(elemCmd.ccmd.i, function (index, cmdValue) {
							$oid.append("<option value=" + 0 + ">" + cmdValue.name + "</option>");
						});
					}
				} else {
					if (typeof(elemCmd.ccmd.i) != 'undefined' || elemCmd.ccmd.i == 0) {
						if (typeof(elemCmd.ccmd.i.oid) != 'undefined') {
							$oid.append("<option value=" + 0 + ">" + elemCmd.ccmd.i.name + "</option>");
						}
					}

				}
			}
		});
		return;
	}
	/********end 场景特例*********/
	var hasMcmd = true;
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			$oid.append("<option select='selected' value=''>" + "" + "</option>");
			if (typeof(elemCmd.mcmd) == 'undefined') {
				hasMcmd = false;
			}
			if (hasMcmd == true) {
				if (typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array) {
					if (elemCmd.mcmd.i != 0) {
						$.each(elemCmd.mcmd.i, function (index, cmdValue) {
							$oid.append("<option value=" + cmdValue.oid + ">" + cmdValue.name + "</option>");
						});
					}
				} else {
					if (typeof(elemCmd.mcmd.i) != 'undefined' || elemCmd.mcmd.i == 0) {
						if (typeof(elemCmd.mcmd.i.oid) != 'undefined') {
							$oid.append("<option value=" + elemCmd.mcmd.i.oid + ">" + elemCmd.mcmd.i.name + "</option>");
						}
					}

				}
			}
		}
	});
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			if (typeof(elemCmd.ccmd) == 'undefined') {
				return;
			}
			if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
				if (elemCmd.ccmd.i != 0) {
					$.each(elemCmd.ccmd.i, function (index, cmdValue) {
						$oid.append("<option value=" + cmdValue.oid + ">" + cmdValue.name + "</option>");
					});
				}
			} else {
				if (typeof(elemCmd.ccmd.i) != 'undefined' || elemCmd.ccmd.i == 0) {
					if (typeof(elemCmd.ccmd.i.oid) != 'undefined') {
						$oid.append("<option value=" + elemCmd.ccmd.i.oid + ">" + elemCmd.ccmd.i.name + "</option>");
					}
				}

			}
		}
	});
}
function InitOidOption(curepid, $oid) {

	$oid.empty();
	/******场景特例******/
	var isScene = false;
	$.each(CurrElemArry, function (index, elem) {
		if (elem.epid == curepid) {
			if (elem.etype == '01') {
				isScene = true;
			}
		}
	});
	if (isScene == true) {
		$.each(CurrElemCMDArry, function (index, elemCmd) {
			if (elemCmd.epid == curepid) {
				$oid.append("<option select='selected' value=''>" + "" + "</option>");
				if (typeof(elemCmd.ccmd) == 'undefined') {
					return;
				}
				if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
					if (elemCmd.ccmd.i != 0) {
						$.each(elemCmd.ccmd.i, function (index, cmdValue) {
							$oid.append("<option value=" + cmdValue.oid + ">" + cmdValue.name + "</option>");
						});
					}
				} else {
					if (typeof(elemCmd.ccmd.i) != 'undefined' || elemCmd.ccmd.i == 0) {
						if (typeof(elemCmd.ccmd.i.oid) != 'undefined') {
							$oid.append("<option value=" + elemCmd.ccmd.i.oid + ">" + elemCmd.ccmd.i.name + "</option>");
						}
					}

				}
			}
		});
		return;
	}
	/********end 场景特例*********/
	var hasMcmd = true;
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			$oid.append("<option select='selected' value=''>" + "" + "</option>");
			if (typeof(elemCmd.mcmd) == 'undefined') {
				hasMcmd = false;
			}
			if (hasMcmd == true) {
				if (typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array) {
					if (elemCmd.mcmd.i != 0) {
						$.each(elemCmd.mcmd.i, function (index, cmdValue) {
							$oid.append("<option value=" + cmdValue.oid + ">" + cmdValue.name + "</option>");
						});
					}
				} else {
					if (typeof(elemCmd.mcmd.i) != 'undefined' || elemCmd.mcmd.i == 0) {
						if (typeof(elemCmd.mcmd.i.oid) != 'undefined') {
							$oid.append("<option value=" + elemCmd.mcmd.i.oid + ">" + elemCmd.mcmd.i.name + "</option>");
						}
					}

				}
			}
		}
	});
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			if (typeof(elemCmd.ccmd) == 'undefined') {
				return;
			}
			if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
				if (elemCmd.ccmd.i != 0) {
					$.each(elemCmd.ccmd.i, function (index, cmdValue) {
						$oid.append("<option value=" + cmdValue.oid + ">" + cmdValue.name + "</option>");
					});
				}
			} else {
				if (typeof(elemCmd.ccmd.i) != 'undefined' || elemCmd.ccmd.i == 0) {
					if (typeof(elemCmd.ccmd.i.oid) != 'undefined') {
						$oid.append("<option value=" + elemCmd.ccmd.i.oid + ">" + elemCmd.ccmd.i.name + "</option>");
					}
				}

			}
		}
	});
}

/*******联动配置管理界面载入oid选项值********/
function LoadOidSelect(curepid, $oid, curroid, currval) {
	/******场景特例******/	
	var isScene = false;
	$.each(CurrElemArry, function (index, elem) {
		if (elem.epid == curepid) {
			if (elem.etype == '01') {
				isScene = true;
			}
		}
	});
	if (isScene == true) {
		$.each(CurrElemCMDArry, function (index, elemCmd) {			
			if (elemCmd.epid == curepid) {
				var oidCmdArray = new Array();
				if (typeof(elemCmd.ccmd) == "undefined") {
					return;
				}
				if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {

					$.each(elemCmd.ccmd.i, function (index, cmdValue) {
							oidCmdArray.push(cmdValue);
					});
				} else {
					if (elemCmd.ccmd.i != 0)
						oidCmdArray.push(elemCmd.ccmd.i);
				}				
				if (oidCmdArray.length == 1) {	
					ChangeSelectByText($oid, oidCmdArray[0].name);
				} else {
					$.each(oidCmdArray, function (index, cmdValue) {
						if (cmdValue.val == currval) {
							ChangeSelectByText($oid, cmdValue.name);
						}
					});
				}

			}
		});
		return;
	}
	/********end 场景特例*********/
	var hasMcmd = true;
	var cmdArry = new Array();
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			var oidCmdArray = new Array();
			if (typeof(elemCmd.mcmd) == "undefined") {
				hasMcmd = false;
			}
			if (hasMcmd == true) {
				if (typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array) {

					$.each(elemCmd.mcmd.i, function (index, cmdValue) {
						if (cmdValue.oid == curroid) {
							cmdArry.push(cmdValue);
							oidCmdArray.push(cmdValue);
						}
					});
				} else {
					if (elemCmd.mcmd.i != 0) {
						if (elemCmd.mcmd.i.oid == curroid) {
							cmdArry.push(elemCmd.mcmd.i);
							oidCmdArray.push(elemCmd.mcmd.i);
						}					
					}
						
				}

				/*if (oidCmdArray.length == 1) {
					ChangeSelectByText($oid, oidCmdArray[0].name);
				} else {
					$.each(oidCmdArray, function (index, cmdValue) {
						if (cmdValue.val == currval) {
							ChangeSelectByText($oid, cmdValue.name);
						}
					});
				}*/
			}
		}
	});
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			var oidCmdArray = new Array();
			if (typeof(elemCmd.ccmd) == "undefined") {
				return;
			}
			if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {

				$.each(elemCmd.ccmd.i, function (index, cmdValue) {
					if (cmdValue.oid == curroid) {
						cmdArry.push(cmdValue);
						oidCmdArray.push(cmdValue);
					}
				});
			} else {
				if (elemCmd.ccmd.i != 0) {
					cmdArry.push(elemCmd.ccmd.i);
					oidCmdArray.push(elemCmd.ccmd.i);
				}					
			}
			/*if(oidCmdArray.length == 1) {
				ChangeSelectByText($oid, oidCmdArray[0].name);
			} else {
			$.each(oidCmdArray, function (index, cmdValue) {
				if (cmdValue.val == currval) {
					ChangeSelectByText($oid, cmdValue.name);
				}
			});
			}*/
		}
	});
	if (cmdArry.length == 1) {
		ChangeSelectByText($oid, cmdArry[0].name);
	}
	for (var i=0; i<cmdArry.length; i++) {
		if (cmdArry[i].oid == curroid && cmdArry[i].val == currval) {
			ChangeSelectByText($oid, cmdArry[i].name);
		}
	}
	
}

/*******判断联动配置管理界面触发值（val）输入框是否需要输入
 * 如果需要则改变val输入框为可输入状态
 * ********/
function SetValState(curepid, currSelectText, $val) {
	/******场景特例******/
	var isScene = false;
	$.each(CurrElemArry, function (index, elem) {
		if (elem.epid == curepid) {
			if (elem.etype == '01') {
				isScene = true;
			}
		}
	});
	if (isScene == true) {
		$.each(CurrElemCMDArry, function (index, elemCmd) {
			if (typeof(elemCmd.ccmd) == "undefined") {
				return;
			}
			if (elemCmd.epid == curepid) {

				$.each(elemCmd.ccmd.i, function (index, cmdValue) {
					if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
						if (cmdValue.name == currSelectText) {
							//判断模板命令val是否为数字，不是则需要输入
							if (!isNaN(cmdValue.val)) {
								$val.val(cmdValue.val);

							} else {
								$val.removeAttr("readonly");
								$val.removeAttr("disabled");
								$val.val(cmdValue.val);

							}

						}
					} else {
						if (elemCmd.ccmd.i.name == currSelectText) {
							//判断模板命令val是否为数字，不是则需要输入
							if (!isNaN(elemCmd.ccmd.i.val)) {
								$val.val(elemCmd.ccmd.i.val);

							} else {
								$val.removeAttr("readonly");
								$val.removeAttr("disabled");
								$val.val(elemCmd.ccmd.i.val);

							}

						}
					}
				});
			}
		});
		return;
	}
	/********end 场景特例*********/
	var hasMcmd = true;
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		hasMcmd = true;
		if (typeof(elemCmd.mcmd) == "undefined") {
			hasMcmd = false;
		}
		if (elemCmd.epid == curepid && hasMcmd == true && elemCmd.mcmd.i != 0) {

			$.each(elemCmd.mcmd.i, function (index, cmdValue) {
				if (typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array) {
					if (cmdValue.name == currSelectText) {
						//判断模板命令val是否为数字，不是则需要输入
						if (!isNaN(cmdValue.val)) {
							$val.val(cmdValue.val);

						} else {
							$val.removeAttr("readonly");
							$val.removeAttr("disabled");
							$val.val(cmdValue.val);

						}

					}
				} else {
					if (elemCmd.mcmd.i.name == currSelectText) {
						//判断模板命令val是否为数字，不是则需要输入
						if (!isNaN(elemCmd.mcmd.i.val)) {
							$val.val(elemCmd.mcmd.i.val);

						} else {
							$val.removeAttr("readonly");
							$val.removeAttr("disabled");
							$val.val(elemCmd.mcmd.i.val);

						}

					}
				}
			});
		}
	});
	$.each(CurrElemCMDArry, function (index, elemCmd) {
		if (elemCmd.epid == curepid) {
			if (typeof(elemCmd.ccmd) == "undefined" || elemCmd.ccmd.i == 0) {
				return;
			}
			$.each(elemCmd.ccmd.i, function (index, cmdValue) {
				if (typeof(elemCmd.ccmd.i) == "object" && elemCmd.ccmd.i.constructor == Array) {
					if (cmdValue.name == currSelectText) {
						//判断模板命令val是否为数字，不是则需要输入
						if (!isNaN(cmdValue.val)) {
							$val.val(cmdValue.val);

						} else {
							$val.removeAttr("readonly");
							$val.removeAttr("disabled");
							$val.val(cmdValue.val);

						}

					}
				} else {
					if (elemCmd.ccmd.i.name == currSelectText) {
						//判断模板命令val是否为数字，不是则需要输入
						if (!isNaN(elemCmd.ccmd.i.val)) {
							$val.val(elemCmd.ccmd.i.val);

						} else {
							$val.removeAttr("readonly");
							$val.removeAttr("disabled");
							$val.val(elemCmd.ccmd.i.val);

						}

					}
				}
			});
		}
	});
}





/*******联动配置管理界面val输入框提示(val输入框焦点进入和离开事件)********/
function SetFocusValue(obj)
{
	var key;
	var $raw = $(obj).closest('tr');
	var $oid = $raw.find('#oid');
	var $val = $raw.find('#val');
	$.each(CurrElemCMDArry,function(index,elemCmd){
	if (typeof(elemCmd.mcmd) == "undefined") {
		return;
	}
	if (elemCmd.epid == nowepid) {
		if(typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array){
		$.each(elemCmd.mcmd.i,function(index,cmdValue){
	 	    if ($oid.val() == cmdValue.oid) {
	 	    	key = cmdValue.val;
    		}									    	
	    });	
		}
		else {
			if ($oid.val() == elemCmd.mcmd.i.oid) {
	 	    	key = elemCmd.mcmd.i.val;
    		}
		}
	}	
});
	if (obj.value == key) {
		$val.val("");
	}
}
function SetBlurValue(obj)
{
	if (obj.value.length != 0) {
		return;
	}
	var key;
	var $raw = $(obj).closest('tr');
	var $oid = $raw.find('#oid');
	$.each(CurrElemCMDArry,function(index,elemCmd){
	if (typeof(elemCmd.mcmd) == "undefined") {
		return;
	}
	if (elemCmd.epid == nowepid) {
		if(typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array){
		$.each(elemCmd.mcmd.i,function(index,cmdValue){
	 	    if ($oid.val() == cmdValue.oid) {
	 	    	key = cmdValue.val;
	 	    	$(obj).val(key);
    		}									    	
	    });	
		}
		else {
			if ($oid.val() == elemCmd.mcmd.i.oid) {
	 	    	key = elemCmd.mcmd.i.val;
	 	    	$(obj).val(key);
    		}	
		}
	}
    });
}

/*******联动设备Reactor表格中val输入框提示(val输入框焦点进入和离开事件)********/
function SetReactorFocusValue(obj)
{
	var key;
	var $raw = $(obj).closest('tr');
	var $oid = $raw.find('#oid');
	var $val = $raw.find('#val');
	var $e_epid = $raw.find('#e_epid');
	$.each(CurrElemCMDArry,function(index,elemCmd){
	if (typeof(elemCmd.mcmd) == "undefined") {
		return;
	}
	if (elemCmd.epid == $e_epid.val()) {
		if(typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array){
		$.each(elemCmd.mcmd.i,function(index,cmdValue){
	 	    if ($oid.val() == cmdValue.oid) {
	 	    	key = cmdValue.val;
    		}									    	
	    });	
		}
		else {
			if ($oid.val() == elemCmd.mcmd.i.oid) {
	 	    	key = elemCmd.mcmd.i.val;
    		}	
		}
	}	
    });
	if (obj.value == key) {
		$val.val("");
	}
}
function SetReactorBlurValue(obj)
{
	if (obj.value.length != 0) {
		return;
	}
	var key;
	var $raw = $(obj).closest('tr');
	var $oid = $raw.find('#oid');
	var $e_epid = $raw.find('#e_epid');
	$.each(CurrElemCMDArry,function(index,elemCmd){
	if (typeof(elemCmd.mcmd) == "undefined") {
		return;
	}
	if (elemCmd.epid == $e_epid.val()) {
		if(typeof(elemCmd.mcmd.i) == "object" && elemCmd.mcmd.i.constructor == Array){
		$.each(elemCmd.mcmd.i,function(index,cmdValue){
	 	    if ($oid.val() == cmdValue.oid) {
	 	    	key = cmdValue.val;
	 	    	$(obj).val(key);
    		}									    	
	    });	
		}
		else {
			if ($oid.val() == elemCmd.mcmd.i.oid) {
	 	    	key = elemCmd.mcmd.i.val;
	 	    	$(obj).val(key);
    		}	
		}
	}
    });
}

/*******联动设备初始化【楼层】选项********/
function InitFloorOption($floorid)
{
	$floorid.empty();
	$floorid.append("<option select='selected' value=''>"+""+"</option>");
	$.each(CurrFloorArry,function(index,elem){		
		$floorid.append("<option value="+elem.id+">"+elem.name+"</option>");	
    });
}
/*******联动配置管理界面载入floorid选项值********/
function LoadFlooridSelect(curfloorid, $floorid)
{
	$.each(CurrElemArry,function(index,elem){				
		if (elem.floorid == curfloorid){
		    ChangeSelectByText($floorid,elem.floorname);
		}
	});
}

/*******联动设备初始化【区域】选项********/
function InitAreaOption(floorid, $aid)
{
	$aid.empty();
	$aid.append("<option select='selected' value=''>"+""+"</option>");
	$.each(CurrAreaArry,function(index,elem){
		if (floorid == elem.floorid) {
			$aid.append("<option value="+elem.id+">"+elem.name+"</option>");
		}			
    });
}
/*******联动配置管理界面载入aid选项值********/
function LoadAidSelect(curaid, $aid)
{
	$.each(CurrElemArry,function(index,elem){				
		if (elem.atype == curaid){
		    ChangeSelectByText($aid,elem.atypename);
		}
	});
}

/*******联动设备初始化【联动设备】选项********/
function InitEpOption(floorid, aid, $e_epid)
{
	$e_epid.empty();
	$e_epid.append("<option select='selected' value=''>"+""+"</option>");
	$.each(CurrElemArry,function(index,elem){
		if (floorid == elem.floorid && aid == elem.atype) {
			$e_epid.append("<option value="+elem.epid+">"+elem.etypename+"</option>");
		}		
    });
}
/*******联动配置管理界面载入e_epid选项值********/
function LoadEpidSelect(curepid, $e_epid)
{
	$.each(CurrElemArry,function(index,elem){				
		if (elem.epid == curepid){
		    ChangeSelectByText($e_epid,elem.etypename);
		}
	});
}